package org.idea.eaglemq.client.consumer;

import com.alibaba.fastjson.JSON;
import org.idea.eaglemq.client.netty.BrokerRemoteRespHandler;
import org.idea.eaglemq.common.coder.TcpMsg;
import org.idea.eaglemq.common.dto.CreateTopicReqDTO;
import org.idea.eaglemq.common.enums.BrokerEventCode;
import org.idea.eaglemq.common.event.EventBus;
import org.idea.eaglemq.common.remote.BrokerNettyRemoteClient;

import java.util.UUID;

/**
 * @author: LunBoWang
 * @description: 创建topic的class
 * @date: 2025/5/13 下午10:24
 * @version: 1.0
 */

public class CreateTopicCommand {
    public static void main(String[] args) {
        BrokerNettyRemoteClient brokerNettyRemoteClient = new BrokerNettyRemoteClient("127.0.0.1", 8990);
        brokerNettyRemoteClient.buildConnection(new BrokerRemoteRespHandler(new EventBus("mq-client-eventbus")));
        CreateTopicReqDTO createTopicReqDTO = new CreateTopicReqDTO();
        createTopicReqDTO.setTopic("dead_queue");
        createTopicReqDTO.setQueueSize(1);
        TcpMsg respMsg = brokerNettyRemoteClient.sendSyncMsg(new TcpMsg(BrokerEventCode.CREATE_TOPIC.getCode(), JSON.toJSONBytes(createTopicReqDTO)), UUID.randomUUID().toString());
        System.out.println("已经创建topic："+createTopicReqDTO.getTopic());
    }
}
